/*
 * Created by Neville Kadwa.
 */
package org.shiftone.cdep.asm;

import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureReader;
import org.apache.log4j.Logger;
import org.shiftone.cdep.model.ClassInfo;

public class CDepSignatureVisitor implements SignatureVisitor
{
    public static final Logger LOG = Logger.getLogger(CDepSignatureVisitor.class);

    private ClassInfo classDep = null;

    public void runSignature(ClassInfo classDep, String signature, boolean isType)
    {
        if (signature != null)
        {
            this.classDep = classDep;
            if (!isType)
            {
                new SignatureReader(signature).accept(this);
            } else {
                new SignatureReader(signature).acceptType(this);
            }
            this.classDep = null;
        }
    }

    public void visitFormalTypeParameter(String name)
    {
//        LOG.debug("visitFormalTypeParameter: " + name);
    }

    public SignatureVisitor visitClassBound()
    {
//        LOG.debug("visitClassBound:");
        return this;
    }

    public SignatureVisitor visitInterfaceBound()
    {
//        LOG.debug("visitInterfaceBound:");
        return this;
    }

    public SignatureVisitor visitSuperclass()
    {
//        LOG.debug("visitSuperclass:");
        return this;
    }

    public SignatureVisitor visitInterface()
    {
//        LOG.debug("visitInterface:");
        return this;
    }

    public SignatureVisitor visitParameterType()
    {
//        LOG.debug("visitParameterType:");
        return this;
    }

    public SignatureVisitor visitReturnType()
    {
//        LOG.debug("visitReturnType:");
        return this;
    }

    public SignatureVisitor visitExceptionType()
    {
//        LOG.debug("visitExceptionType:");
        return this;
    }

    public void visitBaseType(char descriptor)
    {
//        LOG.debug("visitBaseType: " + descriptor);
    }

    public void visitTypeVariable(String name)
    {
        LOG.debug("visitTypeVariable: " + name);
        classDep.addClassCall(name);
    }

    public SignatureVisitor visitArrayType()
    {
//        LOG.debug("visitArrayType:");
        return this;
    }

    public void visitClassType(String name)
    {
        LOG.debug("visitClassType: " + name);
        classDep.addClassCall(name);
    }

    public void visitInnerClassType(String name)
    {
        LOG.debug("visitInnerClassType: " + name);
        classDep.addClassCall(name);
    }

    public void visitTypeArgument()
    {
//        LOG.debug("visitTypeArgument:");
    }

    public SignatureVisitor visitTypeArgument(char wildcard)
    {
//        LOG.debug("visitTypeArgument: " + wildcard);
        return this;
    }

    public void visitEnd()
    {
//        LOG.debug("visitEnd Signature");
    }

}
